package com.xmim.fulcrum.node;

import java.util.Objects;

/**
 * IM节点的POJO类
 * create by CAOYOU
 **/

public class DefaultFulcrumNode implements FulcrumNode {

    private static final long serialVersionUID = -499010884211304846L;
    //节点ID
    protected Long id;
    //服务 IP
    protected String host;
    //服务 端口
    protected Integer port;
    //节点路径
    protected String path;

    private boolean valid;

    public void setId(Long id) {
        this.id = id;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public void setValid(boolean valid) {
        this.valid = valid;
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public String getHost() {
        return host;
    }

    @Override
    public Integer getPort() {
        return port;
    }

    @Override
    public String getPath() {
        return path;
    }

    @Override
    public boolean isValid() {
        return valid;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        DefaultFulcrumNode node = (DefaultFulcrumNode) o;
//        return id == node.id &&
        return Objects.equals(host, node.host) &&
                Objects.equals(port, node.port);
    }


    @Override
    public int compareTo(FulcrumNode o) {
        Long weight1 = this.id;
        Long weight2 = o.getId();
        if (weight1 > weight2) {
            return 1;
        } else if (weight1 < weight2) {
            return -1;
        }
        return 0;
    }

    @Override
    public String toString() {
        return "DefaultFulcrumNode{" +
                "id=" + id +
                ", host='" + host + '\'' +
                ", port=" + port +
                ", path='" + path + '\'' +
                ", valid=" + valid +
                '}';
    }
}
